package com.ds.lens.data.common.util;

import com.ds.lens.data.common.constant.AggregatorEnum;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * describe:
 *
 * @author wangyiming
 * @date 2019/07/29
 */
@Data
public class MetricId {
    private String datasource;
    private Map<String, String> keyByFields;
    private String metricName;
    private String aggrMethod;
    private long timeWindow;

    public MetricId() {
        this.keyByFields = new HashMap<>();
    }

    public void setAggrMethod(String aggr) {
        this.aggrMethod = (aggr == null ? "" : aggr.toUpperCase());
        try {
            if (this.aggrMethod != null) {
                AggregatorEnum.valueOf(aggrMethod);
            }
        } catch (Exception e) {
            this.aggrMethod = "";
        }
    }

    public void addKeyByField(String key, String value) {
        this.keyByFields.put(key, value);
    }
}
